package  
{
	import org.flixel.*;
	
	/**
	 * @author ...
	 */
	
	public class OpeningCinematicState extends FlxState
	{
		//[Embed(source = "../data/gfx/Cinematic.png")] private var _cinematicImg:Class;
		
		private var _counter:Number = 0;
		private const _timeLimit:Number = 8;
		private const _fadeInTime:Number = 1;
		private const _fadeOutTime:Number = 1;
		
		private var _worldsFairText1:FlxText;
		private var _worldsFairText2:FlxText;
		private var _storyText:FlxText;
		
		//private var _cinematicSprite:FlxSprite;
		
		override public function create():void 
		{
			//_cinematicSprite = new FlxSprite(0, 0, _cinematicImg);
			//add(_cinematicSprite);
			
			_worldsFairText1 = new FlxText(0, FlxG.height / 2 - 100, FlxG.width, "April 30, 1893").setFormat("PowellAntique", 30, 0xffffff, "center");
			_worldsFairText1.alpha = 0;
			add(_worldsFairText1);
			
			_worldsFairText2 = new FlxText(0, FlxG.height / 2 - 50, FlxG.width, "Eve of Chicago Columbian Exposition").setFormat("PowellAntique", 24, 0xffffff, "center");
			_worldsFairText2.alpha = 0;
			add(_worldsFairText2);
			
			_storyText = new FlxText(0, _worldsFairText2.y + 50, FlxG.width, "Nikola Tesla finds his lighting sabotaged and must act quickly!").setFormat("PowellAntique", 20, 0xffffff, "center");
			_storyText.alpha = 0;
			add(_storyText);
			
			FlxG.music.fadeOut(1.0);
		}
		
		override public function update():void 
		{	
			super.update();
			
			_counter += FlxG.elapsed;
			
			if (_counter < _fadeInTime)
			{
				_worldsFairText1.alpha = _counter / _fadeInTime;
				_worldsFairText2.alpha = _counter / _fadeInTime;
				_storyText.alpha = _counter / _fadeInTime;
			}
			
			if (_counter > _timeLimit - _fadeOutTime)
			{
				_worldsFairText1.alpha = ((_timeLimit - _counter) / _fadeOutTime);
				_worldsFairText2.alpha = ((_timeLimit - _counter) / _fadeOutTime);
				_storyText.alpha = ((_timeLimit - _counter) / _fadeOutTime);
			}
			
			if (_counter >= _timeLimit)
			{
				FlxG.state = new Level0State;
			}
		}
		
	}

}